package com.imagesystem.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.imagesystem.common.annotation.Log;
import com.imagesystem.common.enums.BusinessType;
import com.imagesystem.system.domain.WashRecord;
import com.imagesystem.system.service.IWashRecordService;
import com.imagesystem.common.core.controller.BaseController;
import com.imagesystem.common.core.domain.AjaxResult;
import com.imagesystem.common.utils.poi.ExcelUtil;
import com.imagesystem.common.core.page.TableDataInfo;

/**
 * 内镜洗消记录Controller
 *
 * @author ruoyi
 * @date 2024-10-11
 */
@Controller
@RequestMapping("/system/record")
public class WashRecordController extends BaseController
{
    private String prefix = "system/record";

    @Autowired
    private IWashRecordService washRecordService;

    @RequiresPermissions("system:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询内镜洗消记录列表
     */
    @RequiresPermissions("system:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WashRecord washRecord)
    {
        startPage();
        List<WashRecord> list = washRecordService.selectWashRecordList(washRecord);
        return getDataTable(list);
    }

    /**
     * 导出内镜洗消记录列表
     */
    @RequiresPermissions("system:record:export")
    @Log(title = "内镜洗消记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WashRecord washRecord)
    {
        List<WashRecord> list = washRecordService.selectWashRecordList(washRecord);
        ExcelUtil<WashRecord> util = new ExcelUtil<WashRecord>(WashRecord.class);
        return util.exportExcel(list, "内镜洗消记录数据");
    }

    /**
     * 新增内镜洗消记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存内镜洗消记录
     */
    @RequiresPermissions("system:record:add")
    @Log(title = "内镜洗消记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WashRecord washRecord)
    {
        return toAjax(washRecordService.insertWashRecord(washRecord));
    }

    /**
     * 修改内镜洗消记录
     */
    @RequiresPermissions("system:record:edit")
    @GetMapping("/edit/{washBatch}")
    public String edit(@PathVariable("washBatch") String washBatch, ModelMap mmap)
    {
        WashRecord washRecord = washRecordService.selectWashRecordByWashBatch(washBatch);
        mmap.put("washRecord", washRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存内镜洗消记录
     */
    @RequiresPermissions("system:record:edit")
    @Log(title = "内镜洗消记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WashRecord washRecord)
    {
        return toAjax(washRecordService.updateWashRecord(washRecord));
    }

    /**
     * 删除内镜洗消记录
     */
    @RequiresPermissions("system:record:remove")
    @Log(title = "内镜洗消记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(washRecordService.deleteWashRecordByWashBatchs(ids));
    }
}
